package com.babble.user.feign;

import com.babble.user.dto.UserOrToUserDTO;
import com.babble.user.entity.UserInfo;
import com.babble.user.entity.UserOauth;
import com.babble.user.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

/**
 * 用户远程接口实现
 */

@RestController
@AllArgsConstructor
@RequestMapping("user")
@Api(value = "用户模块(Feign)", tags = "用户接口远程调用模块")
public class UserClient implements IUserClient {

	private IUserService userService;

	@Override
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "用户信息", notes = "根据用户id获取用户信息")
	@GetMapping("/user-info-by-id")
	public R<UserInfo> userInfo(String userId) {
		return R.data(userService.userInfo(userId));
	}

	@Override
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "评论用户信息", notes = "评论模块获取评论人和被评论人的用户名和头像")
	@GetMapping("/user-or-to-user-by-id")
	public R<UserOrToUserDTO> userInfoOrToUserinfo(@RequestParam("userId") String userId, @RequestParam(value = "toUserId", required = false) String toUserId) {
		return R.data(userService.userInfoOrToUserinfo(userId, toUserId));
	}

	@Override
	@GetMapping("/user-info")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "用户登录", notes = "输入用户信息登录博客")
	public R<UserInfo> userInfo(String username, String password) {
		return R.data(userService.userInfo(username, password));
	}

	@Override
	@PostMapping("/user-auth-info")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "第三方登录", notes = "扫码或者账号密码")
	public R<UserInfo> userAuthInfo(UserOauth userOauth) {
		return R.data(userService.userInfo(userOauth));
	}
}
